<template>
  <el-card class="box-card">
    <div style="line-height: 0px">
      <el-form :inline="true" class="demo-form-inline" size="small">
        <el-form-item>
          <el-input
            v-model="formInline.deptName"
            clearable
            placeholder="部门名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="queryList()">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            type="danger" 
            @click="deleteList()"
            :disabled="multipleSelection.length === 0"
            >删除</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        stripe
        :data="deptList"
        style="width: 100%"
        :cell-style="{'text-align':'center'}"
        :header-cell-style="{'text-align':'center'}"
        row-key="deptId"
        :tree-props="{children:'children', hasChildren:'hasChildren'}"
      >
        <el-table-column class="table-selection" type="selection" width="55"></el-table-column>
        <el-table-column prop="deptId" label="部门id" width="100">
        </el-table-column>
        <el-table-column prop="deptName" label="部门名称" width="150">
        </el-table-column>
        <el-table-column prop="orderNum" label="显示排序" width="100">
        </el-table-column>
        <el-table-column prop="status" label="状态" width="120">
        </el-table-column>
        <el-table-column prop="leader" label="部门领导" width="120">
        </el-table-column>
        <el-table-column prop="phone" label="电话" width="250">
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
      </div>
    </div>
  </el-card>
</template>
<script>
export default {
  name: "dept",
  data() {
    return {
      rowData: {
        deptId: "",
        parentId:"",
        deptName: "",
        orderNum: "",
        phone: "",
        email: "",
        status: "",
        createBy: "",
        createTime:"",
        updateBy:"",
        updateTime:"",
      },
      multipleSelection: [],
      formInline: {
        deptName: "",
      },
      deptList: [],
      pageIndex: 1,
      pageSize: 10,
      total: 0,
    };
  },
  methods: {
    deleteList() {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http
            .post("/sys/sysDept/deleteList", this.multipleSelection)
            .then((res) => {
              if (res.data.data > 0) {
                this.$message({
                  type: "success",
                  message: "删除成功!共删除" + res.data.data + "条记录",
                });
                this.queryList();
              } else {
                this.$message({
                  type: "warning",
                  message: "系统繁忙!",
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleSelectionChange(val) {
      this.multipleSelection = [];
      val.forEach((element) => {
        this.multipleSelection.push(element.id);
      });
    },
    handleDelete(index, row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http
            .get("/sys/sysDept/deleteOne?id=" + row.id)
            .then((res) => {
              
              if (res.data.data) {
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
                this.queryList();
              } else {
                this.$message({
                  type: "warning",
                  message: "系统繁忙!",
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.queryList();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.queryList();
    },
    queryList() {
      this.$http.get("/sys/sysDept/queryList?deptName="+this.formInline.deptName).then((res) => {
        console.log(res)
        this.deptList = res.data.data;
      });
    },
  },
  mounted() {
    this.queryList();
  },
};
</script>

<style lang="less" scoped>
.form-input {
  margin-left: -100px;
}
/deep/ .el-form-item__error {
  margin-left: -100px;
}
/deep/ .cell {
  padding-left: 10px;
}
</style>